package com.zkx.fssb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zkx.fssb.domain.po.Bouquet;

import com.zkx.fssb.domain.po.Flower;
import com.zkx.fssb.exception.BaseException;
import com.zkx.fssb.mapper.BouquetMapper;
import com.zkx.fssb.result.PageQuery;
import com.zkx.fssb.service.BouquetService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class BouquetServiceImpl extends ServiceImpl<BouquetMapper, Bouquet> implements BouquetService {

    @Override
    public Page customPage(PageQuery pageQuery) {

        Page page = new Page(pageQuery.getPageNo(), pageQuery.getPageSize());
        LambdaQueryWrapper<Bouquet> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(pageQuery.getBouquetName() != null, Bouquet::getBouquetName, pageQuery.getBouquetName())
                .eq(pageQuery.getBouquetStatus() != null, Bouquet::getBouquetStatus, pageQuery.getBouquetStatus())
                .orderByDesc(Bouquet::getBouquetSort);
        this.page(page, wrapper);
        List<Bouquet> records = page.getRecords();
        records = records.stream().map(item -> {
            if (item.getBouquetStock() == 0) {
                item.setBouquetStatus(0);
            }
            return item;
        }).collect(Collectors.toList());

        return page;
        
        
        
    }

    @Override
    public void customUpdate(Bouquet bouquet) {
        if (bouquet.getBouquetId() == null) {

            throw new BaseException("更新失败，花束id不能为空");
        }

        this.getBaseMapper().updateById(bouquet);




    }
}
